package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Attention;
import cn.wolfcode.trip.base.domain.Tag;
import cn.wolfcode.trip.base.mapper.AttentionMapper;
import cn.wolfcode.trip.base.mapper.TagMapper;
import cn.wolfcode.trip.base.query.AttentionQueryObject;
import cn.wolfcode.trip.base.service.IAttentionService;
import cn.wolfcode.trip.base.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AttentionServiceImpl implements IAttentionService {
    @Autowired
    private AttentionMapper attentionMapper;

    /**
     * 为用户增加一条关注
     * @param attention
     */
    public void save(Attention attention) {
        attentionMapper.insert(attention);
    }

    /**
     * 根据用户id查询对应所有的关注数以及粉丝数
     * @param qo
     * @return
     */
    public Map getAttentionsAndFansCountById(AttentionQueryObject qo) {
        HashMap map = new HashMap();
        map.put("fans",attentionMapper.selectForFanCountById(qo));
        map.put("attentions",attentionMapper.selectForAttentionCountById(qo));
        return map;
    }

    /**
     * 判断用户是否具有某个粉丝id
     * @param qo
     * @return
     */
    public boolean isAttentioin(AttentionQueryObject qo) {
        Attention attention = attentionMapper.selectForFanById(qo);
        if(attention==null){
            return true;
        }
        return false;
    }

    /**
     * 删除用户的粉丝
     * @param attention
     */
    public void delete(Attention attention) {
        attentionMapper.deleteFan(attention);
    }
}